package com.atguigu.gmall.product.config;

import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;


@Component
@Log4j2
public class ReturnAndConfirmConfig implements RabbitTemplate.ReturnCallback,RabbitTemplate.ConfirmCallback {
    /**
     * confirm 回调确认消息传到交换机
     * @param correlationData
     * @param b
     * @param s
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean b, String s) {
        if (!b){
           log.error("消息发送方到交换机失败，失败原因为为"+s+"消息内容为"+correlationData);
        }
    }

    /**
     * 确认消息传到队列
     * @param message
     * @param i
     * @param s
     * @param s1
     * @param s2
     */
    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {
        log.error("消息发送到队列失败，失败的商品的Id为："+new String(message.getBody()));
    }
}
